From 93a71c0081dd8cb382c8d079a6dfefc30a7cc9eb Mon Sep 17 00:00:00 2001 From: robertl Date: Thu, 26 Jun 2008 20:28:13 +0000 Subject: [PATCH] Add max time to position filter. --- jeeps/gpslibusb.c | 2 +- position.c | 20 ++++++++++++++++++-- xmldoc/filters/options/position-time.xml | 9 +++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 xmldoc/filters/options/position-time.xml diff --git a/jeeps/gpslibusb.c b/jeeps/gpslibusb.c index a629e4bf9..20b531381 100644 --- a/jeeps/gpslibusb.c +++ b/jeeps/gpslibusb.c @@ -325,7 +325,7 @@ int garmin_usb_scan(libusb_unit_data *lud, int req_unit_number) * that is wants to read and write GPX files on a * mounted drive. Try that now. */ - gdx = gdx_find_file(".", NULL); + gdx = gdx_find_file("."); if (gdx) return 1; /* Plan C. */ fatal("Found no Garmin USB devices.\n"); diff --git a/position.c b/position.c index 42247d249..cc0527252 100644 --- a/position.c +++ b/position.c @@ -31,8 +31,11 @@ static route_head *cur_rte = NULL; static double pos_dist; +static double max_diff_time; static char *distopt = NULL; +static char *timeopt = NULL; static char *purge_duplicates = NULL; +static int check_time; typedef struct { double distance; @@ -45,6 +48,8 @@ arglist_t position_args[] = { {"all", &purge_duplicates, "Suppress all points close to other points", NULL, ARGTYPE_BOOL, ARG_NOMINMAX }, + {"time", &timeopt, "Maximum time in seconds beetween two points", + NULL, ARGTYPE_FLOAT | ARGTYPE_REQUIRED, ARG_NOMINMAX }, ARG_TERMINATOR }; @@ -66,7 +71,7 @@ position_runqueue(queue *q, int nelems, int qtype) queue * elem, * tmp; waypoint ** comp; int * qlist; - double dist; + double dist, diff_time; int i = 0, j, anyitem; comp = (waypoint **) xcalloc(nelems, sizeof(*comp)); @@ -91,8 +96,12 @@ position_runqueue(queue *q, int nelems, int qtype) /* convert radians to integer feet */ dist = (int)(5280*radtomiles(dist)); - + diff_time = fabs( waypt_time(comp[i]) - waypt_time(comp[j]) ); + if (dist <= pos_dist) { + if(check_time && diff_time >= max_diff_time) + continue; + qlist[j] = 1; switch (qtype) { case wptdata: @@ -177,6 +186,8 @@ position_init(const char *args) { char *fm; pos_dist = 0; + max_diff_time = 0; + check_time = 0; if (distopt) { pos_dist = strtod(distopt, &fm); @@ -186,6 +197,11 @@ position_init(const char *args) { pos_dist *= 3.2802; } } + + if (timeopt) { + check_time = 1; + max_diff_time = strtod(timeopt, &fm); + } } void diff --git a/xmldoc/filters/options/position-time.xml b/xmldoc/filters/options/position-time.xml new file mode 100644 index 000000000..b12bee718 --- /dev/null +++ b/xmldoc/filters/options/position-time.xml @@ -0,0 +1,9 @@ + + Specifies the maximum time in seconds between any two points. If the + time difference is larger than what's specified here, the points will + not be discarded. + + + This is useful if you have multiple tracks of the same course and you'd + like the filter to consider the tracks the same. + -- 2.30.2